﻿using System;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Net;
using System.Xml;
using System.Collections.Generic;

using FRL.DebtChased.Extensions;

#if WORKFLOWEDITOR
using FRL.DebtChased.WorkflowEditor;
#endif //

#if REPOSITORY
using FRL.DebtChased.Repository;
#endif // #if REPOSITORY

namespace FRL.DebtChased.WorkflowObjects
{

	/// <summary>
	/// Declaration of WorkflowAction_Search class
	/// Workfloe action for performing a manual or automated search
	/// </summary>
	public class WorkflowAction_Search : WorkflowAction_Base
	{

		/////////////////////////////////////////////////////////////
		// Enumerations

		public enum eMethod
		{
			NotSet,
			Google_Manual,
			Google_Automatic,
			CreditSearch_Manual,
			CreditSearch_Automatic,
			Other
		}

		/////////////////////////////////////////////////////////////
		// Constants

		public const string XmlElementName = "WorkflowAction_Search";
		public const string BoingLabel = "Search";

		/////////////////////////////////////////////////////////////
		// Attributes

		private eMethod m_Method = eMethod.NotSet;
		public eMethod Method
		{
			get { return m_Method; }
			set { m_Method = value; }
		}

		private string m_strMessageForCollector;
		public string MessageForCollector
		{
			get { return m_strMessageForCollector; }
			set { m_strMessageForCollector = value; }
		}

		/////////////////////////////////////////////////////////////
		// Implementation

		protected override string _getElementName()
		{
			return XmlElementName;
		}

#if WORKFLOWEDITOR
		public override string GetBoingLabel()
		{
			return BoingLabel;
		}
#endif // #if WORKFLOWEDITOR

#if WORKFLOWEDITOR
		public override string[] GetBoingSubStrings()
		{

			// Declare return variable
			string[] Ftmp = new string[2];

			// Show message in top row
			Ftmp[0] = MethodToDescription(m_Method);

			// Show message for collector
			if (string.IsNullOrEmpty(m_strMessageForCollector))
				Ftmp[1] = "[no message for collector]";
			else
				Ftmp[1] = m_strMessageForCollector;

			// Return variable
			return Ftmp;

		}
#endif // #if WORKFLOWEDITOR

		protected override void _writeParameters(XmlWriter w)
		{

			// Write members as parameters
			w.WriteAttributeString("method", ((int)m_Method).ToString());
			w.WriteAttributeString("msgForCollector", m_strMessageForCollector);

		}

		protected override void _readParameters(XmlReader r)
		{

			// Read parameters
			m_Method = (eMethod)r.SafeReadIntAttribute("method", (int)eMethod.Other);
			m_strMessageForCollector = r.GetAttribute("msgForCollector");

		}

		public override string GetSummary(Workflow.eSummaryFormat SummaryFormat)
		{

			// Declare return variable
			string strFtmp = null;

			// Compare formats
			if (SummaryFormat == Workflow.eSummaryFormat.Audit)
			{
				strFtmp = "Search";
			}
			else if (SummaryFormat == Workflow.eSummaryFormat.Clockwork)
			{
				strFtmp = "Search";
			}
#if DEBUG
			else
				Debug.Assert(false);
#endif // #if DEBUG

			// Return variable
			return strFtmp;

		}

#if REPOSITORY
		public override List<AccountNote> Process(DebtChasedEntities ent, Account acc, AccountInvoice inv)
		{

			// Declare return variable
			List<AccountNote> Ftmp = null;

			// Return variable
			return Ftmp;

		}
#endif // #if REPOSITORY

		/////////////////////////////////////////////////////////////
		// Static operations

		public static string MethodToDescription( eMethod Method )
		{

			// Declare return variable
			string strFtmp = null;

			// Compare methods
			switch (Method)
			{
				case eMethod.Google_Manual:
					strFtmp = "Google Search (User)";
					break;
				case eMethod.Google_Automatic:
					strFtmp = "Google Search (Auto)";
					break;
				case eMethod.CreditSearch_Manual:
					strFtmp = "Credit Search (User)";
					break;
				case eMethod.CreditSearch_Automatic:
					strFtmp = "Credit Search (Auto)";
					break;
				case eMethod.Other:
					strFtmp = "Other (see notes)";
					break;
				default:
					strFtmp = string.Empty;
					break;
			} // switch

			// Return variable
			return strFtmp;

		}

	}

}
